package cloud.take.off.service.order.impl;

import cloud.take.off.mapper.order.OrderItemMapper;
import cloud.take.off.module.order.entity.OrderItem;
import cloud.take.off.mybatis.base.BaseServiceImpl;
import cloud.take.off.service.order.IOrderItemService;
import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @Description: TODO
 * @Author: Take-off
 * @Date: 2024/10/9 1:54 PM
 * @Param
 * @return
 * @Version: 1.0
 **/
@Service
@AllArgsConstructor
public class OrderItemServiceImpl extends BaseServiceImpl<OrderItemMapper,OrderItem> implements IOrderItemService{

    @Override
    public void deleteByOrderId(Long orderId){
        List<OrderItem> orderItems = list(Wrappers.<OrderItem>lambdaQuery().eq(OrderItem::getOrderId, orderId));
        if (CollectionUtil.isNotEmpty(orderItems)){
            deleteLogic(orderItems.stream().map(OrderItem::getId).collect(Collectors.toList()));
        }
    }

    @Override
    public void deleteByOrderId(List<Long> orderIds){
        List<OrderItem> orderItems = list(Wrappers.<OrderItem>lambdaQuery().in(OrderItem::getOrderId, orderIds));
        if (CollectionUtil.isNotEmpty(orderItems)){
            deleteLogic(orderItems.stream().map(OrderItem::getId).collect(Collectors.toList()));
        }
    }

    @Override
    public List<OrderItem> listByOrderId(Long orderId){
        return list(Wrappers.<OrderItem>lambdaQuery().eq(OrderItem::getOrderId, orderId));
    }

}
